package com.edu.exam.enums.exam;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 冲突类型枚举
 * 管理考试安排中的各种冲突类型
 *
 * @author System
 * @version 1.0.0
 */
public enum ConflictType implements BaseEnum {

    TIME_CONFLICT("TIME_CONFLICT", "时间冲突", 1),
    ROLE_CONFLICT("ROLE_CONFLICT", "角色冲突", 2),
    QUALIFICATION_CONFLICT("QUALIFICATION_CONFLICT", "资质冲突", 3),
    WORKLOAD_CONFLICT("WORKLOAD_CONFLICT", "工作量冲突", 4),
    AVAILABILITY_CONFLICT("AVAILABILITY_CONFLICT", "可用时间冲突", 5),
    DUPLICATE_ASSIGNMENT("DUPLICATE_ASSIGNMENT", "重复安排", 6),
    LOCATION_CONFLICT("LOCATION_CONFLICT", "地点冲突", 7),
    VENUE_CONFLICT("VENUE_CONFLICT", "场地冲突", 8),
    INVIGILATOR_CONFLICT("INVIGILATOR_CONFLICT", "监考人员冲突", 9),
    STUDENT_CONFLICT("STUDENT_CONFLICT", "学生冲突", 10),
    EQUIPMENT_CONFLICT("EQUIPMENT_CONFLICT", "设备冲突", 11),
    RESOURCE_CONFLICT("RESOURCE_CONFLICT", "资源冲突", 12),
    CAPACITY_CONFLICT("CAPACITY_CONFLICT", "容量冲突", 13),
    POLICY_CONFLICT("POLICY_CONFLICT", "政策冲突", 14),
    OTHER("OTHER", "其他", 99);

    private final String code;
    private final String description;
    private final int order;

    ConflictType(String code, String description, int order) {
        this.code = code;
        this.description = description;
        this.order = order;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    public int getOrder() {
        return order;
    }

    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果编码无效
     */
    public static ConflictType fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("Conflict type code cannot be null or empty");
        }

        for (ConflictType value : values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        throw new IllegalArgumentException("Unknown conflict type code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值，null如果未找到
     */
    public static ConflictType fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            return null;
        }

        for (ConflictType value : values()) {
            if (value.getDescription().equals(description)) {
                return value;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}